﻿package mortal.game.view.guild.hintIcon
{
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.mvc.core.*;

    public class GuildInviteIcon extends HintBaseIcon
    {

        public function GuildInviteIcon()
        {
            super(ImagesConst.guild_yaoIcon);
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            var dealInviteCallback:Function;
            var inviteInfo:SPlayerInviteInfo;
            var e:* = event;
            super.clickHandler(e);
            if (Cache.instance.guild.inviteList.length == 1)
            {
                dealInviteCallback = function (param1:int) : void
            {
                var _loc_2:* = new Object();
                _loc_2.invitePlayerId = inviteInfo.inviter.entityId.id;
                _loc_2.guildId = inviteInfo.guild.guildId;
                _loc_2.type = inviteInfo.mode;
                if (param1 == Alert.OK)
                {
                    _loc_2.agree = true;
                    if (Cache.instance.guild.selfGuildInfo.guildID != 0)
                    {
                        GameProxy.guild.exitGuildWithoutMsg();
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_DEAL_INVITE, _loc_2));
                }
                else
                {
                    _loc_2.agree = false;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_DEAL_INVITE, _loc_2));
                }
                return;
            }// end function
            ;
                inviteInfo = Cache.instance.guild.inviteList.shift() as SPlayerInviteInfo;
                Alert.show(inviteInfo.inviter.name + Language.getStringByParam(71127, inviteInfo.guild.guildName), null, Alert.OK | Alert.CANCEL, null, dealInviteCallback);
                if (!GuildInviteListPanel.instance.isHide)
                {
                    GuildInviteListPanel.instance.update();
                }
            }
            else if (Cache.instance.guild.inviteList.length > 1)
            {
                GuildInviteListPanel.instance.show();
            }
            if (Cache.instance.guild.inviteList.length == 0)
            {
                this.hide();
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            setLabel(Cache.instance.guild.inviteList.length);
            return;
        }// end function

    }
}
